import { EntityModel } from '@midwayjs/orm';
import { BaseEntity } from 'midwayjs-cool-core';
import { Column, PrimaryGeneratedColumn } from 'typeorm';

/**
 * 商品 SPU
 * 分类：属于当前分类、以及所有祖先分类（一般只存储叶结点分类即可）
 */
@EntityModel('mall_product')
export class MallProductEntity extends BaseEntity {
  @PrimaryGeneratedColumn({ comment: '产品 id' })
  id: number;

  @Column({ comment: '标题' })
  title: string;

  @Column({ comment: '海报/封面图' })
  poster: string;

  @Column({
    default: false,
    comment: '状态',
  })
  sale: boolean;

  // 商品可以属于多个叶结点分类
  @Column({ type: 'simple-array', comment: 'ManyToMany: product => category' })
  categoryId: number[];

  // 默认将分类信息加入到关键字列表中
  @Column({
    type: 'simple-array',
    comment: '关键字',
    nullable: true,
  })
  keyword: string[];

  @Column({
    type: 'simple-array',
    comment: 'OneToMany: product => picture',
    nullable: true,
  })
  carousel: string[];

  @Column({
    type: 'simple-array',
    comment: 'OneToMany: product => picture',
    nullable: true,
  })
  detail: string[];
}
